﻿[[title=" "]]
<script type="text/javascript" language="javascript">
    window.onload = function () {
        document.all("treeDiv").style.display = "none";
        InitTree();
        document.all("treeDiv").style.display = "";
        $('#saveRoles').click(function () {
            //debugger;
            var rCode = wmsCommon.getQueryValue("rCode");
            var nodes = wmsTree_.getCheckedNodes(); //getChangeCheckedNodes();
            //  var formatNodes = formatCheckedTree(nodes);
            var model = wmsCommon.getQueryValue('model');
            var jsStr = wmsCommon.objToJsonStr(formatChecked(nodes));
            jsStr = jsStr.replace(/"/g, "\\\"");
            var saveExpr = "sys(#RoleManager.SaveTreeNodes(" + rCode + ",quote{" + jsStr + "}," + model + "))";
            var result = wmsCommon.execCommand(saveExpr);
            if (result != undefined) {
                if (confirm("保存成功!是否关闭窗口?"))
                    window.close();
            }
        });
    }
    function InitTree() {
                //debugger;
        wmsCommon.setTreeDivStyle("treeDiv", 0.7, 60);
        var rCode = wmsCommon.getQueryValue('rCode');
        var rName = wmsCommon.getQueryValue('rName');
        var modelName = wmsCommon.getQueryValue('model')
        document.title = rName + "角色-> 功能授权";
        document.getElementById('mytitle').innerHTML = rName + " 角色->功能权限";
        var selMethExpr = "sys(#RoleManager.GetRoleCheckTree(" + rCode + "," + modelName + "))";
        var checkedNodes = eval(wmsCommon.execCommand(selMethExpr));
        var ztreeNode = wmsTree_.getNodes();
        var treeNodes = wmsTree_.transformToArray(ztreeNode);

        for (var j = 0; j < checkedNodes.length; j++) {
            for (var i = 0; i < treeNodes.length; i++) {
                if (checkedNodes[j].moduleWBS == treeNodes[i].wbs) {
                    //wmsTree_.getNodesByParam("wbs", treeNodes[i].wbs).checked = true;
                    treeNodes[i].checked = true;
                    break;
                }
            }
        }
        wmsTree_.refresh();
        //wmsTree_.expandAll(true);
        wmsTree_.expandNode(wmsTree_, true, false);
    }
    function formatChecked(nodes) {
        var chNode = new Array();
        for (var i = 0; i < nodes.length; i++) {
            var tempO = new Object();

            tempO.Check = nodes[i].checked;
            if (nodes[i].isParent) {  //非功能点
                tempO.Mask = 0;
                tempO.Wbs = nodes[i].wbs;
            }
            else {
                tempO.Mask = nodes[i].value;
                tempO.Wbs = nodes[i].key;

            }
            chNode.push(tempO);
        }
        return chNode;
    }

    function changeWindowSize() {
        wmsCommon.setTreeDivStyle("treeDiv", 0.7, 60);
    }

</script>
<h3 id="mytitle" style="font-size: 14px; color: Blue; font-style: italic;"></h3>
<div id="treeDiv" style="text-align: center; border: 1px solid #d8e1f9">
    $dataContext.CreateControl("displayType=tree,checkable=true;data=sys(#RoleManager.GetFunModuleTree());")
</div>
<input type="button" value="保存" class="imgBtn" id="saveRoles" />
